package lost_and_found.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.orm.ibatis.SqlMapClientTemplate;


import board.util.Utilities;

import to.HistoryTO;
import to.LostAndFoundTO;
import to.MemberTO;

public class LostAndFoundDAO {
	private SqlMapClientTemplate sqlMap;
	public LostAndFoundDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}	
	//board테이블에 내용을 하나 insert
	public Object insertContentForNewCount(LostAndFoundTO lfto) throws SQLException{
		return sqlMap.insert("insertContentForNewCount2", lfto);
							 
	}
	public Object insertContentForReply(LostAndFoundTO lfto) throws SQLException{
		return sqlMap.insert("insertContentForReply2", lfto);
	}
	public ArrayList<LostAndFoundTO> selectLostListByPage(int page) throws SQLException{
		HashMap map = new HashMap();
		map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
		map.put("page", page);
		return (ArrayList<LostAndFoundTO>)sqlMap.queryForList("selectLostListByPage", map);
	}
	//페이징 없이 전체 조회
	public ArrayList<LostAndFoundTO> selectLostAllList() throws SQLException{
		return (ArrayList<LostAndFoundTO>)sqlMap.queryForList("selectLostAllList");
	}
	
	//총 게시물 수를 return 하는 메소드
	public int selectTotalContent() throws SQLException{
		return (Integer)sqlMap.queryForObject("selectTotalContent2");
	}
	public int updateViewCount(int no) throws SQLException{
		return sqlMap.update("updateViewCount2", no);
	}

	public LostAndFoundTO selectContentByNO(int no) throws SQLException{
		return (LostAndFoundTO)sqlMap.queryForObject("selectContentByNO2", no);
	}
	//게시물 정보를 수정하는 메소드
	public int updateContent(LostAndFoundTO lfto) throws SQLException{
		return sqlMap.update("updateContent2",lfto);
	}
	//글번호로 글을 삭제하는 메소드
	public int deleteContentByNO(int no) throws SQLException{
		return sqlMap.delete("deleteContentByNO2", no);
	}
	//답변 처리시 restep값 update하는 메소드
	public int updateRestep(int refamily, int restep) throws SQLException{
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("refamily", refamily);
		map.put("restep", restep);
		return sqlMap.update("updateRestep2", map);
	}
	
	
}
